// MusicX Program for PCMod (CLIENT)

PROG.PName = "MusicX"
PROG.Author = "[GU]|ZLC|thomasfn"

PROG.NiceName = "MusicX Player"

PROG.SoundList = {
	 { "HL2 - Introduction Song", "music/hl2_intro.mp3" },
	 { "HL2 - Song 1", "music/hl2_song1.mp3" },
	 { "HL2 - Song 2", "music/hl2_song2.mp3" },
	 { "HL2 - Song 3", "music/hl2_song3.mp3" },
	 { "HL2 - Song 4", "music/hl2_song4.mp3" },
	 { "HL2 - Song 6", "music/hl2_song6.mp3" },
	 { "HL2 - Song 7", "music/hl2_song7.mp3" },
	 { "HL2 - Song 8", "music/hl2_song8.mp3" },
	 { "HL2 - Song 10", "music/hl2_song10.mp3" },
	 { "HL2 - Song 11", "music/hl2_song11.mp3" },
	 { "HL2 - Song 12", "music/hl2_song12_long.mp3" },
	 { "HL2 - Song 13", "music/hl2_song13.mp3" },
	 { "HL2 - Song 14", "music/hl2_song14.mp3" },
	 { "HL2 - Song 15", "music/hl2_song15.mp3" },
	 { "HL2 - Song 16", "music/hl2_song16.mp3" },
	 { "HL2 - Song 17", "music/hl2_song17.mp3" },
	 { "HL2 - Song 19", "music/hl2_song19.mp3" },
	 { "HL2 - Song 20 (A)", "music/hl2_song20_submix0.mp3" },
	 { "HL2 - Song 20 (B)", "music/hl2_song20_submix4.mp3" },
	 { "HL2 - Suit Song", "music/hl2_song23_SuitSong3.mp3" },
	 { "HL2 - Song 25", "music/hl2_song25_Teleporter.mp3" },
	 { "HL2 - Song 26", "music/hl2_song26.mp3" },
	 { "HL2 - Song 27", "music/hl2_song27_trainstation2.mp3" },
	 { "HL2 - Song 28", "music/hl2_song28.mp3" },
	 { "HL2 - Song 29", "music/hl2_song29.mp3" },
	 { "HL2 - Song 30", "music/hl2_song30.mp3" },
	 { "HL2 - Song 31", "music/hl2_song31.mp3" },
	 { "HL2 - Song 32", "music/hl2_song32.mp3" },
	 { "HL2 - Song 33", "music/hl2_song33.mp3" },
	 { "Portal - Still Alive", "music/portal_still_alive.mp3" }
}

function PROG:BuildWindow( WindowName, Desktop, Object )
	//DInterface:AddLabel( "lblInfo", Desktop, "WireClient V1", 5, 5 )
	
	if (WindowName == "Main") then
		
		DInterface:AddButton( "btnPlay", Desktop, "Play", Object:GetWide()*0.55, 50, 60, 20, function()
			local lineid = DInterface:GetTableSelectedLine( "tblSounds", Desktop, "Sound Name" )
			if ((lineid) && (lineid != 0)) then
				local sname = DInterface:GetObject( "tblSounds", "tbl", Desktop ).Lines[ lineid ].SName
				SendCommand( "play", sname )
			end
		end )
		
		
		DInterface:AddButton( "btnStop", Desktop, "Stop", Object:GetWide()*0.55, 75, 60, 20, function()
			SendCommand( "stop" )
		end )
		
		DInterface:AddLabel( "lblStatus", Desktop, "", Object:GetWide()*0.55, 100 )
		
		DInterface:AddTable( "tblSounds", Desktop, 5, 35, Object:GetWide()*0.5, Object:GetTall()-40 )
		DInterface:TableAddColumn( "tblSounds", Desktop, "Sound Name" )
		for _, v in pairs( self.SoundList ) do
			local row = DInterface:TableAddRow( "tblSounds", Desktop, v[1] )
			row.SName = v[2]
		end
		
		SendCommand( "getstatus" )
		
	end
	
	DInterface:AddButton( "btnQuit", Desktop, "X", Object:GetWide()-20, 0, 20, 20, function() SendCommand( "quit" ); end )
end

function PROG:ClearWindow( Desktop )
	
	DInterface:RemoveTable( "tblSounds", Desktop )
	
	DInterface:RemoveButton( "btnPlay", Desktop )
	DInterface:RemoveButton( "btnStop", Desktop )
	
	DInterface:RemoveLabel( "lblStatus", Desktop )
	
	DInterface:RemoveButton( "btnQuit", Desktop )
end

// Data[1] = Tag
// Data[2] = Content
function PROG:DataRecieved( Desktop, Data )
	if (Data[1] == "status") then
		local snd = Data[2]
		local new_snd = snd
		for _, v in pairs( self.SoundList ) do
			if (snd == v[2]) then new_snd = v[1] end
		end
		DInterface:SetLabelText( "lblStatus", Desktop, new_snd )
	end
end

function PROG:Paint( x, y, w, h )
	// draw.SimpleText( self.NiceName, "SmallPCText", x + (w*0.05), y + (h*0.05), Color( 255, 255, 255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
end